/*
 * UnixInput.cpp
 *
 *  Created on: Feb 10, 2012
 *      Author: hzheng
 */

#include "lcd/UnixInput.h"
#include "errorcode.h"
#include "typedefine.h"
#include "UpKeyPressEvent.h"
#include "DownKeyPressEvent.h"
#include "EnterKeyPressEvent.h"
#include "EscKeyPressEvent.h"
#include "KeyboardEvent.h"

namespace NS_LCD_AFW
{

CUnixInput::CUnixInput()
{
}

CUnixInput::~CUnixInput()
{
}

#ifdef ENABLE_LIB_NCURSES
#include <ncurses.h>
int CUnixInput::readChar(char & c, int timeout)
{

	halfdelay(timeout * 10);
	if ((c = getch()) < 0)
	{
		return ERR_WAIT_TIMEOUT;
	}
	return ERR_SUCCESS;
}

CKeyboardEvent *CUnixInput::translateCodeToEvent(char c)
{
	CKeyboardEvent *pEvent = NULL;
	switch ((int)c)
	{
	case 3://UP
	{
		OBJ_NEW(CUpKeyPressEvent,pEvent);
	}
		break;
	case 2://DOWN
	{
		OBJ_NEW(CDownKeyPressEvent,pEvent);
	}
		break;
	case 5://KEY_RIGHT:
	{
		OBJ_NEW(CEnterKeyPressEvent,pEvent);
	}
		break;
	case 4://LEFT
	{
		OBJ_NEW(CEscKeyPressEvent,pEvent);
	}
		break;
	default:
	{
//		OBJ_NEW(CKeyboardEvent,pEvent);
//		pEvent->setParam(c);
	}
		break;
	}
	return pEvent;
}
#else
int CUnixInput::readChar(char & c, int timeout)
{
	return ERR_SUCCESS;
}

CKeyboardEvent *CUnixInput::translateCodeToEvent(char c)
{
	return NULL;
}
#endif

} /* namespace NS_LCD_AFW */
